{% load static %}
{% load utils %}
{% load manager_inquiry_tags %}
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="renderer" content="webkit">
<title>询价管理</title>
<link rel="stylesheet" href="{% static '/public/css/ui.css' %}">
<link rel="stylesheet" href="{% static '/public/admin/css/layout.css' %}">
<script src="{% static '/public/js/jquery.js' %}"></script>
<script src="{% static '/public/js/ui.js' %}"></script>
</head>

<body>
    <div class="position">当前位置：扩展管理 > <a href="{% url 'manager:inquiry_index' %}">询价管理</a></div>
    <div class="border">
        <!---->
        <div class="navbar">
            <div class="lefter">
                
                <a href="javascript:;" class="ui-btn ui-btn-info ui-dropdown-show ui-mr-sm" data-target="#dropdown-1">批量操作</a>
                <div class="ui-dropdown" id="dropdown-1">
                    <li><a href="javascript:;" class="ui-dropdown-item btach" type="1">设为已处理</a></li>
                    <li><a href="javascript:;" class="ui-dropdown-item btach" type="2">设为未处理</a></li>
                    <div class="ui-dropdown-line"></div>
                    <li><a href="javascript:;" class="ui-dropdown-item btach" type="3">批量删除</a></li>
                </div>
                <span class="ui-btn-group ui-btn-group-yellow ui-btn-group-bg">
                    <a class="ui-btn-group-item{% if types == 0 %} active{% endif %}" href="{% url 'manager:inquiry_index' %}?type=0">全部</a>
                    <a class="ui-btn-group-item{% if types == 1 %} active{% endif %}" href="{% url 'manager:inquiry_index' %}?type=1">未处理</a>
                    <a class="ui-btn-group-item{% if types == 2 %} active{% endif %}" href="{% url 'manager:inquiry_index' %}?type=2">已处理</a>
                </span>
            </div>
            
            <div class="righter">
                <form action="{{ request.build_absolute_uri }}">
                    <div class="ui-form-group">
                        <div class="ui-input-group">
                            <input type="text" name="keyword" class="ui-form-ip radius-right-none" value="{{ keyword|default_if_none:'' }}" placeholder="请输入关键字">
                            <button type="submit" class="after"><div class="ui-icon-search"></div></button>
                        </div>
                    </div>
                </form>
            </div>
            
        </div>
        
        <form method="post" class="ui-form">
        {% manager_inquiry_list %}
        {% csrf_token %}
        </form>
        <!---->
    </div>

<script>
    const csrftoken = document.querySelector('[name=csrfmiddlewaretoken]').value;
$(function()
{
	$(".edit-iframe").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialogbox(
		{
			'title':"询价处理",
			'text':url,
			'width':'650px',
			'height':'400px',
			'type':3,
			'oktheme':'ui-btn-info',
			'ok':function(e)
			{
				e.iframe().contents().find("#wmcms-submit").click();
			}
		});
	});
	$('.ui-switch input[type=checkbox]').on('click',function()
	{
		var url=$(this).attr("data-url");
		var result=($(this).is(':checked'))?1:0;
		$.ajax(
		{
			url:url,
			type:"post",
			dataType:'json',
            headers: {'X-CSRFToken': csrftoken},
            mode: 'same-origin',
			data:"&state="+result,
			error:function(e){alert(e.responseText);},
			success:function(d)
			{
				if(d.state=='success')
				{
					wmcms.success(d.msg);
				}
				else
				{
					wmcms.error(d.msg);
				}
			}
		});
	});
    $(".btach").click(function()
	{
		var type=$(this).attr("type");
		var data=[];
		$(".ui-form").find("input[type=checkbox]:checked").each(function()
		{
			if($(this).attr("class")!='checkall' && !$(this).closest("label").hasClass("ui-switch"))
			{
				data.push($(this).val());
			}
		});
        if(data.length==0)
        {
            wmcms.error('至少选择一条内容');
        }
        else
        {
            $.ajax(
			{
                type:'post',
                cache:false,
                dataType:'json',
                url:'{% url "manager:inquiry_btach" %}',
                headers: {'X-CSRFToken': csrftoken},
                mode: 'same-origin',
                data:'id='+data.join(",")+'&type='+type,
                error:function(e){alert(e.responseText);},
                success:function(d)
				{
                    if(d.state=='success')
                    {
                        wmcms.success(d.msg);
                        setTimeout(function(){location.href='{% url "manager:inquiry_index" %}';},1500);
                    }
                    else
                    {
                        wmcms.error(d.msg);
                    }
                }
            });
        }
    });
    $(".del").click(function()
	{
		var url=$(this).attr("data-url");
		$.dialog(
		{
			'title':"操作提示",
			'text':"确定要删除？不可恢复！",
			'oktheme':'ui-btn-info',
			'ok':function(e)
			{
				$.ajax(
				{
                    url:url,
					type:'post',
					dataType:'json',
					headers: {'X-CSRFToken': csrftoken},
                    mode: 'same-origin',
					error:function(e){alert(e.responseText);},
                    success:function(d)
                    {
                        e.close();
                        if(d.state=='success')
                        {
                            wmcms.success(d.msg);
                            setTimeout(function(){location.href='{% url "manager:inquiry_index" %}';},1000);
                        }
                        else
                        {
                            wmcms.error(d.msg);
                        }
                    }
                });
			}
		});
    });
})
</script>
</body>
</html>